const path = require('path');
const axios = require('axios');
const FileSystem = require('./utils/fileSystem');
const GenerateTSModal = require('./utils/generateTSModal');

class Iconfont {
    constructor(options) {
        this.baseUrl = options.baseUrl;
        this.output = path.resolve(process.cwd(), options.output);
        this.utils = {
            fs   : new FileSystem(this.output),
            model: new GenerateTSModal(this.output)
        };
        this.download();
    }
    async download() {
        await this.utils.fs.removeDir();
        const { data } = await axios.get(this.baseUrl, {
            responseType: 'stream',
            headers     : {
                'Cookie': 'cna=8WEiFVMq9CgCAXTqkdpNprvo; hasViewVideo=true; EGG_SESS_ICONFONT=U8AXvqwdm-42-umGXGwgKq_Emj2wuVCkA87TjZ3dn6xm2T4whio3sIKoy4kjkuBSusLMQ-0MhcjWBE1FwhfGmMbpO9xPCEANAHIhoET_7kLMg-qVGhDYJaXU8YYDzntAGc2y-mrQgCfFo0I4F4Tp8VghFNjhjWeI_l35HOv26R1Oo9PlmTpE7KBMVIyIbX4ZoJish3p6eVVHnAypuda6B5iyGclx7ZJWqZzj1y-8CN4dAkyyOaA6xE1YArEfkFcG28FYyJltLwhAhzBJIXmesqkeGZVJoSXNt_UwCkONoy8Un825-ZTEUUR4YIoWpMykT9vH1qMzRdguzRYZ6jfI279rH09QpXKsMj4d9o8FYqEcYg3OgXngNnse3JUVdTuY0MRK6e_JH9dcBQY-R1q2_n0kg_tLQYlW3825QKixRglYXZEold5_GcxNyziTnmjTPGrEkGQv5OirCeoGbRYuIMdKjWKCjhD6JYyqKyVXPQSn_1bX0GMMXMS4g7eVdAlFZOEK_TEvUceEFNueV5XG76urh1UYqJF7KNqbr9ymInbGGvgHi8LIuf1seyk5nzs0R8E1h4EXbT0oTdKI5-pLjjbBCV70IXBmsVs0K1Gk0eIPrkIieNzgO5Da37yWUkMf0LEJoknpCt5qWoJgMXqZEW4fkZ76lwWIKWfv8JqiOHFLS98QSEJ6X5XId5I6WERzXfEJ-WFBZgLI72dzFPYnZ_Jtgyk_E43_fjvGjjCU58WO1kLgjhP-EX7nL7NTBYp1mf84TABYoSr0GeDVCjjYRtCAf3x6fodL1Soi3tEYC3i_lkAF6I2UBTHv8T9oiI48LDDBPJywncyRyZ1WvFQsUuuCtd-gwPfAoCtI7rkYD7EpmucM-Cm_rAtl9SPa46PUz301yA_10v4s6XZbhk5UR1GJVXIb8vKL_Zaf08fkZWfEF4OaWfM-6zO1GSAJZqDIVGlcvnFQUxSpD7kogqVWAt7he6ZAkxI0Hh25H8BLh9xll91jh6wkJIenoa0M2_R_eznjpjn5vMyae7OQozCyyCicmImlE_Yx7O_n3LKSpwgLofVRV03q5yzqub5Rrctd0fqDuAJxi-VUU195KT2I4fo7yypGpjIGjPqRli1uHN1g1SwxWODtUbQcbUbZRRqje_DLDJbfpZ2D1v_3Rw-JUnnw8Got65mt_QPPZ3s5gKCApPixk6aYcZ-RYPLecERRg0kl5r5Tq_e4afBQMbwrWR82DhAD5uqQwfYMX-uZtAYx3np_SqjP1Nq1EJPKXvF93KKYk-nEHIGJkzew2Rt0JA==; trace=AQAAAJ/Xx0yM2QAAZ3VWZZGyYWIpAOzq; ctoken=Y0ICJec1y9VtHPmEpYdkINAR; u=4209238; u.sig=NwsTHFvNZ2ZcuoH2zw2iBzo5jAvrYjV99HwPjXWwSnI; UM_distinctid=17288e4ef2b285-08bb43c2f96f6d-36664c08-1fa400-17288e4ef2cefb; CNZZDATA1253813504=1911988683-1591434366-https%253A%252F%252Fwww.iconfont.cn%252F%7C1591434366; isg=BGpqxy6VwP5zok_4_ME1kOMmu9AM2-41u4upA_QiIr1JJwjh3GhURRARt1M712bN'
            }
        });
        const url = await this.utils.fs.createIconfontDir(data);
        this.utils.model.createH5Model(url, 'model');
        this.utils.model.createRNModel(url, 'model');
    }
}
module.exports = Iconfont;